<!DOCTYPE html>
<html>
<head>
    {include file="_Fragment/meta" /}
    <link rel="stylesheet" href="/static/pear/component/pear/css/pear.css" />
    <link rel="stylesheet" href="/static/pear/admin/css/other/console1.css" />
</head>
<body class="pear-container">

<div class="layui-row layui-col-space10">
    <div class="layui-col-xs6 layui-col-md3">
        <div class="layui-card top-panel">
            <div class="layui-card-header">已学人数</div>
            <div class="layui-card-body">
                <div class="layui-row layui-col-space5">
                    <div class="top-panel-number" style="color: #28333E;" id="value1">
                        <i class="layui-icon layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop"></i>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="layui-col-xs6 layui-col-md3">
        <div class="layui-card top-panel">
            <div class="layui-card-header">已学完人数</div>
            <div class="layui-card-body">
                <div class="layui-row layui-col-space5">
                    <div class="top-panel-number" style="color: #28333E;" id="value2">
                        <i class="layui-icon layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop"></i>
                    </div>

                </div>
            </div>
        </div>
    </div>
    <div class="layui-col-xs6 layui-col-md3">
        <div class="layui-card top-panel">
            <div class="layui-card-header">播放量</div>
            <div class="layui-card-body">
                <div class="layui-row layui-col-space5">
                    <div class="top-panel-number" style="color: #28333E;" id="value3">
                        <i class="layui-icon layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop"></i>
                    </div>

                </div>
            </div>
        </div>
    </div>
    <div class="layui-col-xs6 layui-col-md3">
        <div class="layui-card top-panel">
            <div class="layui-card-header">总学习时长(H)</div>
            <div class="layui-card-body">
                <div class="layui-row layui-col-space5">
                    <div class="top-panel-number" style="color: #28333E;" id="value4">
                        <i class="layui-icon layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop"></i>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="layui-col-xs6 layui-col-md3">
        <div class="layui-card top-panel">
            <div class="layui-card-header">分享总量</div>
            <div class="layui-card-body">
                <div class="layui-row layui-col-space5">
                    <div class="top-panel-number" style="color: #28333E;" id="value5">
                        <i class="layui-icon layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop"></i>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="layui-col-xs6 layui-col-md3">
        <div class="layui-card top-panel">
            <div class="layui-card-header">发帖总量</div>
            <div class="layui-card-body">
                <div class="layui-row layui-col-space5">
                    <div class="top-panel-number" style="color: #28333E;" id="value6">
                        <i class="layui-icon layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop"></i>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="layui-col-xs6 layui-col-md3">
        <div class="layui-card top-panel">
            <div class="layui-card-header">点赞总量</div>
            <div class="layui-card-body">
                <div class="layui-row layui-col-space5">
                    <div class="top-panel-number" style="color: #28333E;" id="value7">
                        <i class="layui-icon layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop"></i>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="layui-col-xs6 layui-col-md3">
        <div class="layui-card top-panel">
            <div class="layui-card-header">评论总量</div>
            <div class="layui-card-body">
                <div class="layui-row layui-col-space5">
                    <div class="top-panel-number" style="color: #28333E;" id="value8">
                        <i class="layui-icon layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop"></i>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="layui-row layui-col-space1">
    <div class="layui-card">
        <div class="layui-card-body">
            <form class="layui-form" lay-filter="reload">
                <div class="layui-form-item">

                    <div class="layui-form-item layui-inline">
                        <div class="layui-input-inline">
                            <select name="type">
                                <option value="">章节类型</option>
                                <option value="1">图文</option>
                                <option value="2">文档</option>
                                <option value="3">测试</option>
                                <option value="4">Survey</option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-form-item layui-inline">
                        <div class="layui-input-inline">
                            <input type="text" name="title" placeholder="章节名称" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <input type="hidden" name="learning_id" value="{$learning_id}">
                    <div class="layui-form-item layui-inline">
                        <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="user-query">
                            <i class="layui-icon layui-icon-search"></i>
                            查询
                        </button>
                        <button type="reset" class="pear-btn pear-btn-md">
                            <i class="layui-icon layui-icon-refresh"></i>
                            重置
                        </button>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <div class="layui-card">
        <div class=" layui-tab layui-tab-card">
            <ul class="layui-tab-title">
                <li>
                    <a href="/LearningContent/user?learning_id={$learning_id}">用户数据</a>
                </li>
                <li class="layui-this">章节数据</li>
            </ul>
            <div class="layui-card-body">
                <table id="user-table" lay-filter="user-table"></table>
            </div>
        </div>
    </div>
</div>


<script type="text/html" id="user-bar">
    <button class="pear-btn pear-btn-primary pear-btn-md" lay-event="view"><i class="layui-icon layui-icon-search"></i></button>
</script>
<script type="text/html" id="create-time">
    {{layui.util.toDateString(d.update_time*1000, 'yyyy-MM-dd HH:mm:ss')}}
</script>
{include file="_Fragment/javascript" /}
<script>
    layui.use(['table', 'form', 'jquery','common', 'count'], function() {
        let table = layui.table;
        let form = layui.form;
        let $ = layui.jquery;
        let common = layui.common;
        let count = layui.count;
        let learning_id = "{$learning_id}";

        let cols = [
            [
                {
                    title: '章节名称',
                    field: 'title',
                    align: 'center',
                    fixed: 'left',
                },
                {
                    title: '类型',
                    field: 'type_name',
                    align: 'center',
                    fixed: 'left',
                },
                {
                    title: '学习人数',
                    field: 'total',
                    align: 'center',
                    sort: true
                },
                {
                    title: '完成人数',
                    field: 'complete_total',
                    align: 'center',
                    sort: true
                },

                {
                    title: '学习时长(H)',
                    field: 'duration',
                    align: 'center',
                    sort: true
                },
                {
                    title: '播放量',
                    field: 'play_total',
                    align: 'center',
                    sort: true
                },
                {
                    title: '更新时间',
                    field: 'update_time',
                    align: 'center',
                    templet: '#create-time'
                },
                {
                    title: '操作',
                    toolbar: '#user-bar',
                    align: 'center',
                }
            ]
        ]

        table.render({
            elem: '#user-table',
            url: '/LearningContent/getChapterrList?learning_id='+learning_id,
            page: {layout:['count', 'prev', 'page', 'next', 'skip']},
            limit: 5,
            cols: cols,
            //skin: 'line',
            toolbar: '#user-toolbar',
            defaultToolbar: [{
                title: '刷新',
                layEvent: 'refresh',
                icon: 'layui-icon-refresh',
            }, 'filter',{
                title: '导出' //标题
                ,layEvent: 'export' //事件名，用于 toolbar 事件中使用
                ,icon: 'layui-icon-export' //图标类名
            }]
        });
        form.on('submit(user-query)', function(data) {
            table.reload('user-table', {
                where: data.field
                ,page: {
                    curr: 1, //重新从第 1 页开始
                    layout:['count', 'prev', 'page', 'next', 'skip']
                }
                ,limit: 5,
            })
            return false;
        });

        //监听排序事件
        table.on('sort(user-table)', function(obj){ //注：sort 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var field = form.val('reload');
            table.reload('user-table', {
                initSort: obj //记录初始排序，如果不设的话，将无法标记表头的排序状态。
                ,where: { //请求参数（注意：这里面的参数可任意定义，并非下面固定的格式）
                    field: obj.field //排序字段
                    ,order: obj.type //排序方式
                    ,title: field.title
                    ,type: field.type
                    ,learning_id: field.learning_id
                }
            });
        });

        table.on('tool(user-table)', function(obj) {
            if (obj.event === 'view') {
                window.view(obj);
            }
        });


        table.on('toolbar(user-table)', function(obj) {
            if (obj.event === 'import') {
                window.import();
            } else if (obj.event === 'refresh') {
                window.refresh();
            } else if (obj.event === 'export') {
                window.export();
            }
        });

        window.view = function(obj) {
            layer.open({
                type: 2,
                title: '详情',
                shade: 0.1,
                area: [common.isModile()?'100%':'900px', common.isModile()?'100%':'600px'],
                content: '/LearningContent/chapterView?resource_id='+obj.data.id
            });

        }

        // 数据导出
        window.export = function() {
            var field = form.val('reload');
            layer.confirm('确定要导出数据吗?', {
                icon: 3,
                title: '提示'
            }, function(index) {
                layer.close(index);
                window.open("{:url('exportChapterrList')}?type="+field.type+"&learning_id="+field.learning_id+"&title="+field.title, "_blank");
            });
        };

        window.refresh = function(param) {
            table.reload('user-table');
        }

        $.ajax({
            url: "/LearningContent/getCount?learning_id="+learning_id,
            dataType: 'json',
            type: 'post',
            success: function(res) {

                count.up("value1", {
                    time: 4000,
                    num: res.data.total,
                    regulator: 50
                })

                count.up("value2", {
                    time: 4000,
                    num: res.data.complete_total,
                    regulator: 50
                })

                count.up("value3", {
                    time: 4000,
                    num: res.data.play_total,
                    regulator: 50
                })
                count.up("value4", {
                    time: 4000,
                    num: res.data.duration,
                    regulator: 50
                })
                count.up("value5", {
                    time: 4000,
                    num: res.data.share_total,
                    regulator: 50
                })

                count.up("value6", {
                    time: 4000,
                    num: res.data.topic_total,
                    regulator: 50
                })

                count.up("value7", {
                    time: 4000,
                    num: res.data.zan_total,
                    regulator: 50
                })
                count.up("value8", {
                    time: 4000,
                    num: res.data.comment_total,
                    regulator: 50
                })
            }
        })
    })
</script>
</body>
</html>
